<template>
	<view class="scrollView">
		<template v-for="(item, index) in chatHomeList" :key="index">
			<!-- ai -->
			<view class="List Left" :id="`chat${index}`" v-if="item.state == 1">
				<view class="HeadBox">
					<image
						:src="imgUrls(mainStore.BaseInfo.chatImg)"
						mode="aspectFill"
						class="Headimgs"></image>
					<view class="d-flex a-center p-top10" v-if="item.isshow">
						<text class="tipTxt">静音</text>
						<image
							:src="staticImg('icon_sound@2x.png')"
							mode="aspectFill"
							class="soundImg"></image>
					</view>
				</view>
				<view class="content" v-if="item.type == 1 || item.type == 3 || item.type == 603">
					<view class="content_text">
						<view class="answer">
							<mp-html :content="item.answer" :markdown="true" />
						</view>

						<!-- 单选 -->
						<template v-if="item.type == 1">
							<view
								class="single_choice"
								v-for="(sub, subIn) in item.recommend"
								:key="subIn"
								@click.stop="single_choice(item, sub, index)"
								>{{ sub.index }}.{{ sub.question }}
							</view>
						</template>
						<!-- 多选 -->
						<view class="rows" v-if="item.type == 3">
							<up-checkbox-group
								v-model="checkboxValue1"
								placement="column"
								@change="checkboxChange">
								<view
									class="Multiple_choice"
									:class="{ Nochoice: !item.allowclick }"
									v-for="(sub, subIn) in item.recommend">
									<up-checkbox
										:customStyle="{ marginBottom: '8px' }"
										:key="subIn"
										size="14"
										labelSize="13"
										iconSize="10"
										:labelColor="mainStore.color"
										:label="`${sub.index}.${sub.question}`"
										:name="sub.question">
									</up-checkbox>
								</view>
							</up-checkbox-group>
							<view
								class="configBtn"
								:class="{ active: checkboxValue1.length }"
								v-if="item.allowclick"
								@click="configMultiple(item)"
								>确定</view
							>
						</view>
						<!-- 选择律师 -->
						<view class="Findlawyer" v-if="item.type == 603">
							<block v-for="(sub, subIndex) in item.lawyers" :key="sub.userId">
								<view
									class="list"
									@click="item.selectUserId = sub.userId"
									:class="{ Active: item.selectUserId == sub.userId }">
									<image
										:src="imgUrls(sub.avatar)"
										mode="aspectFill"
										class="headImg"
										@click.stop="
											toUrl(`/pages/counselors/details?id=${sub.id}`)
										"></image>
									<view class="content">
										<text class="Name">{{ sub.realName }}</text>
										<text class="desc">律师</text>
									</view>
									<view class="seleBox">
										<view class="iconfont icon-xuanzhong"></view>
									</view>
								</view>
							</block>
							<view
								class="configBtn"
								:class="{ active: item.selectUserId }"
								@click="Choicelawyer(item)"
								v-if="!item.orgQuestion"
								>选择</view
							>
						</view>
					</view>
				</view>
				<view class="content" v-else>
					<view class="content_text bgFa">
						<view class="answer">
							{{ item.answer }}
						</view>
					</view>
					<!-- 跳转 -->
					<view class="skip" v-if="item.type == 601" @click="skipUrl(item)">
						<text class="nameTitle">{{ item.tourlDescription }}</text>
						<view class="iconfont icon-xiangyou color-999 size44"></view>
					</view>
				</view>
			</view>

			<!-- 用户 -->
			<view class="List Right" :id="`chat${index}`" v-if="item.state == 2">
				<view class="content">
					<view class="content_text">{{ item.question }}</view>
					<view class="Edit_error" v-if="item.isshow">
						<text class="discern">识别错误？</text>
						<text class="Edit" @click.stop="Editpop(index)">修改</text>
					</view>
				</view>
				<view class="HeadBox">
					<image
						:src="imgUrls(mainStore.userInfo.avatar)"
						mode="aspectFill"
						class="Headimgs"></image>
				</view>
			</view>
		</template>
	</view>
</template>

<script setup>
	import { toUrl, Toast, staticImg, imgUrls, showLoading, hideLoading } from '@/utils/utils.js';
	import Http from '@/utils/request.js';
	import { ref, computed, watch, nextTick, onUnmounted } from 'vue';
	import { onLoad, onShow, onReady, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
	import { useMainStore } from '@/stores/index';

	const mainStore = useMainStore();
	const props = defineProps(['chatHomeList']);
</script>

<style lang="scss" scoped>
	.scrollView {
		width: 100%;
		box-sizing: border-box;

		.List {
			width: 100%;
			display: flex;
			padding: 20rpx 20rpx 0 20rpx;
			.content {
				width: 100%;

				.bgFa {
					background-color: #fbfbfb !important;
				}

				&_text {
					display: inline-block;
					padding: 0 20rpx;
					background-color: #ffffff;

					font-size: 28rpx;
					line-height: 40rpx;
					margin-top: 20rpx;
				}
			}

			.HeadBox {
				display: flex;
				flex-direction: column;
				align-items: center;

				.Headimgs {
					width: 88rpx;
					height: 88rpx;
					border-radius: 4rpx;
					overflow: hidden;
				}
			}
		}

		.Left {
			padding-right: 130rpx;
			justify-content: flex-start;

			.content_text {
				border-radius: 0 20rpx 20rpx 20rpx;
				border: 1rpx solid rgba(0, 0, 0, 0.1);

				.answer {
					color: #333;
					font-size: 28rpx;
				}

				.single_choice {
					width: 100%;
					padding: 14rpx 20rpx;
					color: $color_008;
					font-size: 26rpx;
					background-color: #f7f7f7;
					margin-bottom: 16rpx;
					border-radius: 6rpx;
				}

				.Multiple_choice {
					width: 100%;
					padding: 4rpx 20rpx;
					color: $color_008;
					font-size: 26rpx;
					background-color: #f7f7f7;
					margin-bottom: 14rpx;
					border-radius: 6rpx;

					::v-deep .u-checkbox__icon-wrap {
						flex-shrink: 0 !important;
					}
				}

				.Nochoice {
					::v-deep .u-checkbox__icon-wrap {
						display: none !important;
					}
				}

				.configBtn {
					width: 100%;
					height: 70rpx;
					background-color: #f7f7f7;
					color: #999;
					font-size: 30rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 10rpx;
					margin-top: 20rpx;
				}

				.active {
					background-color: $color_008 !important;
					color: #fff !important;
				}
			}

			.tipTxt {
				color: #9a9ea2;
				font-size: 20rpx;
			}

			.soundImg {
				width: 28rpx;
				height: 24rpx;
				margin-left: 4rpx;
			}

			.content {
				margin-left: 20rpx;
			}
		}

		// 跳转
		.skip {
			width: 80%;
			background-color: #fff;
			margin-top: 20rpx;
			display: flex;
			align-items: center;
			padding: 30rpx 24rpx;
			border-radius: 0 20rpx 20rpx 20rpx;

			.nameTitle {
				color: #000;
				font-size: 28rpx;
				flex: 1;
			}
		}

		.Findlawyer {
			width: 100%;
			display: flex;
			flex-direction: column;
			padding-bottom: 20rpx;
			.list {
				width: 100%;
				background-color: #f7f7f7;
				padding: 16rpx 20rpx;
				border-radius: 10rpx;
				margin-bottom: 20rpx;
				display: flex;
				align-items: center;
				.headImg {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					margin-right: 14rpx;
				}
				.content {
					width: 240rpx;
					flex: 1;
					display: flex;
					align-items: center;
					.Name {
						color: #000;
						font-size: 30rpx;
					}
					.desc {
						color: #9a9ea2;
						font-size: 24rpx;
						margin-left: 20rpx;
					}
				}
				.seleBox {
					width: 42rpx;
					height: 42rpx;
					border-radius: 50%;
					border: 1px solid #e1e1e1;
					margin-left: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					overflow: hidden;
					.icon-xuanzhong {
						color: #f7f7f7;
						font-size: 32rpx;
					}
				}
			}
			.Active {
				.seleBox {
					background-color: #13c643;
					border: 1px solid #13c643;
					.icon-xuanzhong {
						color: #fff;
					}
				}
			}
		}

		.Right {
			padding-left: 130rpx;
			justify-content: flex-end;

			.content {
				margin-right: 20rpx;
				display: flex;
				flex-direction: column;
				align-items: flex-end;

				.content_text {
					color: #fff;
					border-radius: 20rpx 0 20rpx 20rpx;
					padding: 14rpx 20rpx;
					background-color: v-bind('mainStore.color');
				}

				.Edit_error {
					display: flex;
					align-items: center;
					padding-top: 10rpx;

					.discern {
						color: #9a9ea2;
						font-size: 20rpx;
					}

					.Edit {
						color: v-bind('mainStore.color');
						font-size: 20rpx;
					}
				}
			}
		}
	}
</style>
